<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts 主体
import resize from './mixins/resize'
import { ActiveNumStatistic } from "@/api/dashboard.js";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    btDat: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
    btDat(name, value) {
      this.lineDate = name
      this.initChart()
    }
  },
  data() {
    return {
      chart: null,
      lineDate: {}
    }
  },
  created() {
    //this.getActiveNumStatistic()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {

    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        //  backgroundColor: 'rgba(1,202,217,.2)',
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['30分钟以内', '30-60分钟', '1小时-2小时', '2小时以上'],
          textStyle: {
            color: 'rgba(255,255,255,.7)'
          },
        },

        series: [
          {
            name: '设备在线时间',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center',
              color: '#fff'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '20',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              { value: this.lineDate.tenMinuteDev, name: '30分钟以内' },
              { value: this.lineDate.tenHalfhourDev, name: '30-60分钟' },
              { value: this.lineDate.halfhourDev, name: '1小时-2小时' },
              { value: this.lineDate.hourDev, name: '2小时以上' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
          // {
          //   name: '设备在线时间',
          //   type: 'pie',
          //   roseType: 'radius',
          //   radius: [15, 95],
          //   center: ['50%', '44%'],
          //   data: [
          //     { value: this.lineDate.tenMinuteDev, name: '30分钟以内' },
          //     { value: this.lineDate.tenHalfhourDev, name: '30-60分钟' },
          //     { value: this.lineDate.halfhourDev, name: '1小时-2小时' },
          //     { value: this.lineDate.hourDev, name: '2小时以上' }
          //   ],
          //   animationEasing: 'cubicInOut',
          //   animationDuration: 2600
          // }
        ]
      })
    }
  }
}

</script>
